# load("//fboss/agent/fbpkg:agent.bzl", "get_all_wedge_agent_csco_path_actions", "get_all_wedge_agent_dnx_path_actions", "get_all_wedge_agent_path_actions")
load("//fboss/agent/fbpkg:agent.bzl", "get_all_wedge_agent_nvda_path_actions")
load(
    "//fboss/agent/fbpkg:test_artifacts.bzl",
    "build_test_artifacts_fbpkgs",
    "get_all_agent_test_path_actions",
    "get_all_fsdb_integration_test_path_actions",
    "get_all_hw_test_path_actions",
    "get_all_invariant_test_path_actions",
    "get_all_link_test_path_actions",
)
load("//fboss/build:fbpkg.bzl", "fboss_fbpkg_builder")
load("//fboss/build:sdk.thrift.bzl", "ProductLine")
load("//fbpkg:fbpkg.bzl", "fbpkg")

oncall("fboss_agent_push")

# TODO: reenable these once they have parity with cfgr pkgs, including test_artifacts

# fbpkg.builder(
#     name = "neteng.fboss.wedge_agent",
#     override_log_paths = [
#         "fboss/agent",
#         "fboss/lib",
#         "neteng/fboss/tools/wrapper_scripts",
#     ],
#     path_actions = get_all_wedge_agent_path_actions(),
#     split_debuginfo = True,
# )

# fbpkg.builder(
#     name = "neteng.fboss.wedge_agent_dnx",
#     override_log_paths = [
#         "fboss/agent",
#         "fboss/lib",
#         "neteng/fboss/tools/wrapper_scripts",
#     ],
#     path_actions = get_all_wedge_agent_dnx_path_actions(),
#     split_debuginfo = True,
# )

# fbpkg.builder(
#     name = "neteng.fboss.wedge_agent_csco",
#     override_log_paths = [
#         "fboss/agent",
#         "fboss/lib",
#         "neteng/fboss/tools/wrapper_scripts",
#     ],
#     path_actions = get_all_wedge_agent_csco_path_actions(),
#     split_debuginfo = True,
# )

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent.test_artifacts.hw_test",
    buck_modes = [
        "opt-asan",
    ],
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.split-dwarf": "true",
            "fbcode.use_link_groups": "true",  # Enable link groups to fix relocation overflow
            "fbcode//cxx.link_weight": "6",  # reduce concurrency to avoid OOM
        },
        num_threads = 20,  # reduce compile parallelism
    ),
    override_log_paths = ["fboss/agent"],
    path_actions = get_all_hw_test_path_actions(),
)

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent.test_artifacts.agent_test",
    buck_modes = [
        "opt-asan",
    ],
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.split-dwarf": "true",
            "fbcode.use_link_groups": "true",  # Enable link groups to fix relocation overflow
            "fbcode//cxx.link_weight": "6",  # reduce concurrency to avoid OOM
        },
        num_threads = 20,  # reduce compile parallelism
    ),
    override_log_paths = ["fboss/agent"],
    path_actions = get_all_agent_test_path_actions(),
)

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent.test_artifacts.link_test",
    buck_modes = [
        "opt-asan",
    ],
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.split-dwarf": "true",
            "fbcode.use_link_groups": "true",  # Enable link groups to fix relocation overflow issues
            "fbcode//cxx.link_weight": "12",  # reduce concurrency to avoid OOM
        },
        num_threads = 20,  # reduce compile parallelism
    ),
    override_log_paths = ["fboss/agent"],
    path_actions = get_all_link_test_path_actions(),
)

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent.test_artifacts.fsdb_integration_test",
    buck_modes = [
        "opt-asan",
    ],
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.split-dwarf": "true",
            "fbcode.use_link_groups": "true",  # Enable link groups to fix relocation overflow
            "fbcode//cxx.link_weight": "6",  # reduce concurrency to avoid OOM
        },
        num_threads = 20,  # reduce compile parallelism
    ),
    override_log_paths = ["fboss/agent"],
    path_actions = get_all_fsdb_integration_test_path_actions(),
)

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent.test_artifacts.invariant_test",
    buck_modes = [
        "opt-asan",
    ],
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.split-dwarf": "true",
            "fbcode.use_link_groups": "true",  # Enable link groups to fix relocation overflow
            "fbcode//cxx.link_weight": "12",  # reduce concurrency to avoid OOM
        },
        num_threads = 20,  # reduce compile parallelism
    ),
    override_log_paths = ["fboss/agent"],
    path_actions = get_all_invariant_test_path_actions(),
)

fboss_fbpkg_builder(
    name = "neteng.fboss.wedge_agent_nvda",
    buck_opts = fbpkg.buck_opts(
        config = {
            "fbcode.enable_distributed_thinlto": "true",
            "fbcode.split-dwarf": "true",
        },
    ),
    fail_on_redundant_configerator_fbpkg = False,
    override_log_paths = [
        "fboss/agent",
        "fboss/lib",
        "neteng/fboss/tools/wrapper_scripts",
    ],
    path_actions = get_all_wedge_agent_nvda_path_actions(),
    split_debuginfo = True,
)

build_test_artifacts_fbpkgs(product_lines = [ProductLine.NVIDIA_SAI_SDK])

#Build LEABA test artifacts fbpkg
build_test_artifacts_fbpkgs(product_lines = [ProductLine.LEABA])

#Build BCM test artifacts fbpkg (All three product lines use the same product name (brcm))
build_test_artifacts_fbpkgs(product_lines = [
    ProductLine.SAI_SDK_BCM,
    ProductLine.BCM_DSF_SDK,
])

#Build BCM_native_sdk test artifacts fbpkg (native_bcm)
build_test_artifacts_fbpkgs(product_lines = [ProductLine.BCM_NATIVE_SDK])
